from django.core.management.base import BaseCommand
from users.models import User, Supplier, DeliveryStaff

class Command(BaseCommand):
    help = '创建初始数据'

    def handle(self, *args, **options):
        # 创建采购员
        if not User.objects.filter(username='purchaser').exists():
            purchaser = User.objects.create_user(
                username='purchaser',
                email='purchaser@example.com',
                password='purchaser123',
                role='purchaser',
                phone='13800138001',
                company_name='采购部',
            )
            self.stdout.write(self.style.SUCCESS('成功创建采购员用户'))

        # 创建销售员
        if not User.objects.filter(username='salesman').exists():
            salesman = User.objects.create_user(
                username='salesman',
                email='salesman@example.com',
                password='salesman123',
                role='salesman',
                phone='13800138002',
                company_name='销售部',
            )
            self.stdout.write(self.style.SUCCESS('成功创建销售员用户'))

        # 创建配送员
        if not User.objects.filter(username='deliveryman').exists():
            deliveryman = User.objects.create_user(
                username='deliveryman',
                email='deliveryman@example.com',
                password='deliveryman123',
                role='deliveryman',
                phone='13800138003',
                company_name='配送部',
            )
            DeliveryStaff.objects.create(
                user=deliveryman,
                vehicle_number='京A12345',
                service_area='北京市朝阳区',
            )
            self.stdout.write(self.style.SUCCESS('成功创建配送员用户'))

        # 创建供应商
        if not User.objects.filter(username='supplier').exists():
            supplier = User.objects.create_user(
                username='supplier',
                email='supplier@example.com',
                password='supplier123',
                role='supplier',
                phone='13800138004',
                company_name='优质供应商有限公司',
                business_license='91110105MA12345678',
            )
            Supplier.objects.create(
                user=supplier,
                company_name='优质供应商有限公司',
                business_license='91110105MA12345678',
            )
            self.stdout.write(self.style.SUCCESS('成功创建供应商用户'))

        # 创建客户
        if not User.objects.filter(username='customer').exists():
            customer = User.objects.create_user(
                username='customer',
                email='customer@example.com',
                password='customer123',
                role='customer',
                phone='13800138005',
                company_name='优质客户有限公司',
            )
            self.stdout.write(self.style.SUCCESS('成功创建客户用户')) 